using TMPro;
using UnityEngine;
using UnityEngine.UI;

[DisallowMultipleComponent]
[ExecuteAlways]
public sealed class LoadingScreen : MonoBehaviour
{
    [Range(0f, 1f)]
    public float progress;
    private void Update()
    {
        var slider = transform.Find("Slider").GetComponent<Slider>();
        float p;
        if (progress != 0 && progress != 1f)
        {
            p = Mathf.Lerp(slider.value, progress, 0.2f);
        }
        else
        {
            p = progress;
        }

        transform.Find("LoadingProgressText").GetComponent<TMP_Text>().text = Mathf.RoundToInt(p * 100) + "%";
        slider.value = p;
    }
}

